package com.fer.t1.client.pages.multiStep;

import com.fer.t1.client.PageManager;
import com.fer.t1.client.Presenter;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.SimplePanel;

public abstract class MultiStepPresenter<T extends MultiStepHandler> extends Presenter<T> implements MultiStepHandler{

	private int currentStep;
	
	public MultiStepPresenter() {
		currentStep = 0;
	}
	
	@Override
	public void setStep(int step)
	{
		System.out.println("MultiStepPresenter.setStep()"+step);
		currentStep = step;
		SimplePanel panel = getView().getPanel();
		Composite comp = getView().getSteps().get(currentStep);
		panel.setWidget(comp);
	}
	
	private MultiStepView getView()
	{
		return (MultiStepView) view;
	}
	
	public void nextStep()
	{
		currentStep++;
		launchHistoryEvent();
	}
	
	public void previousStep()
	{
		currentStep--;
		launchHistoryEvent();
	}

	private void launchHistoryEvent() {

		PageManager.goTo(url, currentStep+1);
		
	}


}
